package com.moweilin.mo_gateway.handlers;

import io.vertx.core.http.HttpServerRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;

/**
 * Created by moweilin on 2017/2/27.
 */
public class SimpleInternalFailureHandler implements IFailureHandler<HttpServerRequest>{
    private static final Logger logger = LoggerFactory.getLogger(SimpleInternalFailureHandler.class);

    @Override
    public void handle(HttpServerRequest request,Exception e) {
        String msg = "";

        if(logger.isDebugEnabled()){
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            msg += "ERROR:\n";
            msg += sw.toString();
        }
        request.response().setStatusCode(HttpURLConnection.HTTP_INTERNAL_ERROR).end(msg);
    }
}
